/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rh.game.loader;

import com.rh.game.Tile;

/**
 *
 * @author hjones
 */
public class Tile1 implements Tile {
    public static final Tile1 NULL = new Tile1((byte) 0, "", "", "", false);

    private boolean walkable = false;
    public boolean isWalkable()  {
        return walkable;
    }
    
    private byte id = 0;
    public byte getID()  { return id; }
    
    private String name = "";
    public String getName()  {
        return name;
    }
    
    private String resource = "";
    public String getResource()  {
        return resource;
    }
    
    private String gridString = "";
    String getGridString()  {
        return gridString;
    }
    
    private Tile1(Tile1 pTile)  {
        this(pTile.getID(), pTile.getName(), pTile.getResource(), pTile.getGridString(), pTile.isWalkable());
    }
    
    private Tile1(byte pID, String pName, String pValue, String pGrid, boolean pWalkable)  {
        super();
        id = pID;
        name = pName;
        resource = pValue;
        gridString = pGrid;
        walkable = pWalkable;
    }
    
    public Tile1 update(String pName, String pValue)  {
        // System.out.println("==> " + pName + ", " + pValue + " on " + this);
        
        Tile1 t = new Tile1(this);
        if (pValue == null)  pValue = "";
        pValue = pValue.trim();
        
        if ("ID".equals(pName))  {
            if (pValue.equals(""))  return this;
            t.id = Byte.valueOf(pValue);
        }
        else if ("Graphic".equals(pName))  {
            t.resource = pValue;
        }
        else if ("Name".equals(pName))  {
            t.name = pValue;
        }
        else if ("GridString".equals(pName))  {
            t.gridString = pValue;
        }
        else if ("Walkable".equals(pName))  {
            t.walkable = Boolean.valueOf(pValue).booleanValue();
        }
        else  {
            return this;
        }

        // System.out.println(t);
        
        return t;
    }
    
    public String toString()  {
        return "Tile1 " + getID() + ", " + getName() + ", " + getResource() + ", " + getGridString() + ", walkable: " + isWalkable(); 
    }
}
